package edu.cqie.smartfarm.exception.handler;


import edu.cqie.smartfarm.exception.annotation.GlobalException;
import edu.cqie.smartfarm.exception.exception.IGlobalException;
import edu.cqie.smartfarm.result.R;
import edu.cqie.smartfarm.result.ResultCodeEnum;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.BatchUpdateException;


/**
 * 数据库批量修改异常
 * BatchUpdateException：通常发生在批处理更新操作发生错误抛出异常时
 *
 * @author shineTan
 * @date 2022/12/23 17:12
 */
@Slf4j
@GlobalException(throwable = BatchUpdateException.class)
public class BatchUpdateExceptionHandler implements IGlobalException<R, BatchUpdateException> {

    @Override
    public R exception(BatchUpdateException throwable, HttpServletRequest request, HttpServletResponse response) {
        log.error(throwable.getMessage());
        return R.Failed(ResultCodeEnum.DUPLICATE_KEY_EXCEPTION.getCode(), "数据已存在，请勿重复操作");
    }
}
